function Mouse(element)
{
	this.position = new Object();
	this.positionOnDown = new Object();
	this.element = element;

	element.mouse = this;
	element.onmouseup = Mouse.onUp;
	element.onmouseout = Mouse.onOut;
	element.onmousedown = Mouse.onDown;
	element.onmousemove = Mouse.onMove;
}

Mouse.onOut = function(e)
{
	this.mouse.boutonState = undefined;
}

Mouse.onUp = function(e)
{
	this.mouse.boutonState = "up";
}

Mouse.onDown = function(e)
{
	this.mouse.boutonState = "down";

	Mouse.calculatePosition(e, this);
	this.mouse.positionOnDown.x = this.mouse.getPosition().x;
	this.mouse.positionOnDown.y = this.mouse.getPosition().y;
}

Mouse.onMove = function(e)
{
	Mouse.calculatePosition(e, this);
}

Mouse.calculatePosition = function(e, ref)
{
	var elt = ref;

	var mX = -elt.offsetLeft,
		mY = -elt.offsetTop;

	while(elt = elt.offsetParent)
	{
		mX += elt.scrollLeft - elt.offsetLeft;
		mY += elt.scrollTop - elt.offsetTop;
	}

	ref.mouse.setPosition(e.clientX+mX, e.clientY+mY);
}

Mouse.prototype.setPosition = function(x, y)
{
	this.position.x = x;
	this.position.y = y;
}

Mouse.prototype.getPositivePosition = function()
{
	return this.position;
}

Mouse.prototype.getPosition = function()
{
	var position = new Object();

	if(this.position.x != undefined)
	{
		position.x = this.position.x - this.element.offsetWidth/2;
		position.y = (this.element.offsetHeight - this.position.y)
						- this.element.offsetHeight/2;
	} else
	{
		position.x = undefined;
		position.y = undefined;
	}

	return position;
}
